using System.Collections.Generic;
using System.Text;

namespace OracleInternal.SqlAndPlsqlParser.LocalParsing
{
	internal class OracleLpSubqueryFactoringClause : OracleLpStatementElement, IOracleLpNamedObjectContainer
	{
		protected List<OracleLpSubqueryFactoringTerm> m_vSubqueryFactoringTerms;

		internal override OracleLpStatementElementType ElementType => OracleLpStatementElementType.SubqueryFactoringClause;

		public List<OracleLpSubqueryFactoringTerm> SubqueryFactoringTerms => m_vSubqueryFactoringTerms;

		public OracleLpSubqueryFactoringClause(OracleLpStatementElement parent)
			: base(parent)
		{
		}

		public void AddSubqueryFactoringTerm(OracleLpSubqueryFactoringTerm term)
		{
			if (m_vSubqueryFactoringTerms == null)
			{
				m_vSubqueryFactoringTerms = new List<OracleLpSubqueryFactoringTerm>(1);
			}
			m_vSubqueryFactoringTerms.Add(term);
			term.Parent = this;
		}

		public void RetrieveNamedObjectReferences(OracleLpStatement statement)
		{
			if (m_vSubqueryFactoringTerms == null)
			{
				return;
			}
			foreach (OracleLpSubqueryFactoringTerm vSubqueryFactoringTerm in m_vSubqueryFactoringTerms)
			{
				vSubqueryFactoringTerm.RetrieveNamedObjectReferences(statement);
			}
		}

		internal override void ToString(StringBuilder sb)
		{
			string depthIndent = base.DepthIndent;
			sb.Append(depthIndent);
			sb.Append("Subquery factoring clause:\n");
			if (m_vSubqueryFactoringTerms == null)
			{
				return;
			}
			foreach (OracleLpSubqueryFactoringTerm vSubqueryFactoringTerm in m_vSubqueryFactoringTerms)
			{
				vSubqueryFactoringTerm.ToString(sb);
			}
		}
	}
}
